// $ANTLR 3.0.1 /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g 2008-05-26 20:06:21

package portelogiche;
import java.util.ArrayList;


import org.antlr.runtime.*;
import java.util.ArrayList;

public class PorteLogicheParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PUNTOVIRGOLA", "VIRGOLA", "APERTA", "CHIUSA", "NOT", "AND", "OR", "CANCELLETTO", "ALFANUMERICO", "WHITESPACE"
    };
    public static final int PUNTOVIRGOLA=4;
    public static final int AND=9;
    public static final int VIRGOLA=5;
    public static final int APERTA=6;
    public static final int EOF=-1;
    public static final int CANCELLETTO=11;
    public static final int CHIUSA=7;
    public static final int NOT=8;
    public static final int OR=10;
    public static final int ALFANUMERICO=12;
    public static final int WHITESPACE=13;

        public PorteLogicheParser(TokenStream input) {
            super(input);
        }
        

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return "/Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g"; }



              public  ArrayList<Port> Ports = new ArrayList();
              public  ArrayList ParserErrors = new ArrayList();

    @Override
            public void emitErrorMessage(String msg) {
                     System.out.println(msg);
                     ParserErrors.add(msg);
    }





    // $ANTLR start expr
    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:58:1: expr : pl ( PUNTOVIRGOLA pl )* ;
    public final void expr() throws RecognitionException {
        try {
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:58:7: ( pl ( PUNTOVIRGOLA pl )* )
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:59:2: pl ( PUNTOVIRGOLA pl )*
            {
            pushFollow(FOLLOW_pl_in_expr149);
            pl();
            _fsp--;

            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:59:5: ( PUNTOVIRGOLA pl )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==PUNTOVIRGOLA) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:59:6: PUNTOVIRGOLA pl
            	    {
            	    match(input,PUNTOVIRGOLA,FOLLOW_PUNTOVIRGOLA_in_expr152); 
            	    pushFollow(FOLLOW_pl_in_expr154);
            	    pl();
            	    _fsp--;


            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end expr


    // $ANTLR start pl
    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:62:1: pl : ( pln | pla | plo );
    public final void pl() throws RecognitionException {
        try {
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:62:4: ( pln | pla | plo )
            int alt2=3;
            switch ( input.LA(1) ) {
            case NOT:
                {
                alt2=1;
                }
                break;
            case AND:
                {
                alt2=2;
                }
                break;
            case OR:
                {
                alt2=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("62:1: pl : ( pln | pla | plo );", 2, 0, input);

                throw nvae;
            }

            switch (alt2) {
                case 1 :
                    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:62:6: pln
                    {
                    pushFollow(FOLLOW_pln_in_pl169);
                    pln();
                    _fsp--;


                    }
                    break;
                case 2 :
                    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:63:5: pla
                    {
                    pushFollow(FOLLOW_pla_in_pl178);
                    pla();
                    _fsp--;


                    }
                    break;
                case 3 :
                    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:64:5: plo
                    {
                    pushFollow(FOLLOW_plo_in_pl184);
                    plo();
                    _fsp--;


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end pl


    // $ANTLR start pln
    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:67:1: pln : NOT APERTA N1= porta VIRGOLA N3= porta CHIUSA ;
    public final void pln() throws RecognitionException {
        String N1 = null;

        String N3 = null;


        try {
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:67:6: ( NOT APERTA N1= porta VIRGOLA N3= porta CHIUSA )
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:68:2: NOT APERTA N1= porta VIRGOLA N3= porta CHIUSA
            {

            	Token token = ((TokenStream)input).LT(1);
            	int line = token.getLine();
            	int col = token.getCharPositionInLine();
            	
            match(input,NOT,FOLLOW_NOT_in_pln200); 
            match(input,APERTA,FOLLOW_APERTA_in_pln204); 
            pushFollow(FOLLOW_porta_in_pln208);
            N1=porta();
            _fsp--;

            match(input,VIRGOLA,FOLLOW_VIRGOLA_in_pln212); 
            pushFollow(FOLLOW_porta_in_pln216);
            N3=porta();
            _fsp--;

             
              	Port not = new Port("NOT",N1,"null",N3,line,col);
              	Ports.add(not);
              	
            match(input,CHIUSA,FOLLOW_CHIUSA_in_pln221); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end pln


    // $ANTLR start pla
    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:81:1: pla : AND APERTA A1= porta VIRGOLA A2= porta VIRGOLA A3= porta CHIUSA ;
    public final void pla() throws RecognitionException {
        String A1 = null;

        String A2 = null;

        String A3 = null;


        try {
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:81:5: ( AND APERTA A1= porta VIRGOLA A2= porta VIRGOLA A3= porta CHIUSA )
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:82:2: AND APERTA A1= porta VIRGOLA A2= porta VIRGOLA A3= porta CHIUSA
            {

            	Token token = ((TokenStream)input).LT(1);
            	int line = token.getLine();
            	int col = token.getCharPositionInLine();
            	
            match(input,AND,FOLLOW_AND_in_pla236); 
            match(input,APERTA,FOLLOW_APERTA_in_pla241); 
            pushFollow(FOLLOW_porta_in_pla245);
            A1=porta();
            _fsp--;

            match(input,VIRGOLA,FOLLOW_VIRGOLA_in_pla249); 
            pushFollow(FOLLOW_porta_in_pla253);
            A2=porta();
            _fsp--;

            match(input,VIRGOLA,FOLLOW_VIRGOLA_in_pla257); 
            pushFollow(FOLLOW_porta_in_pla261);
            A3=porta();
            _fsp--;

             
            	Port and = new Port("AND",A1,A2,A3,line,col);
            	Ports.add(and);
            	
            match(input,CHIUSA,FOLLOW_CHIUSA_in_pla266); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end pla


    // $ANTLR start plo
    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:96:1: plo : OR APERTA O1= porta VIRGOLA O2= porta VIRGOLA O3= porta CHIUSA ;
    public final void plo() throws RecognitionException {
        String O1 = null;

        String O2 = null;

        String O3 = null;


        try {
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:96:6: ( OR APERTA O1= porta VIRGOLA O2= porta VIRGOLA O3= porta CHIUSA )
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:97:2: OR APERTA O1= porta VIRGOLA O2= porta VIRGOLA O3= porta CHIUSA
            {

            	Token token = ((TokenStream)input).LT(1);
            	int line = token.getLine();
            	int col = token.getCharPositionInLine();
            	
            match(input,OR,FOLLOW_OR_in_plo282); 
            match(input,APERTA,FOLLOW_APERTA_in_plo286); 
            pushFollow(FOLLOW_porta_in_plo290);
            O1=porta();
            _fsp--;

            match(input,VIRGOLA,FOLLOW_VIRGOLA_in_plo296); 
            pushFollow(FOLLOW_porta_in_plo300);
            O2=porta();
            _fsp--;

            match(input,VIRGOLA,FOLLOW_VIRGOLA_in_plo306); 
            pushFollow(FOLLOW_porta_in_plo310);
            O3=porta();
            _fsp--;

             
              	Port or = new Port("OR",O1,O2,O3,line,col);
              	Ports.add(or);
              	
            match(input,CHIUSA,FOLLOW_CHIUSA_in_plo317); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end plo


    // $ANTLR start porta
    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:112:1: porta returns [String nome] : ( ALFANUMERICO | CANCELLETTO );
    public final String porta() throws RecognitionException {
        String nome = null;

        Token ALFANUMERICO1=null;
        Token CANCELLETTO2=null;

        try {
            // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:118:2: ( ALFANUMERICO | CANCELLETTO )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==ALFANUMERICO) ) {
                alt3=1;
            }
            else if ( (LA3_0==CANCELLETTO) ) {
                alt3=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("112:1: porta returns [String nome] : ( ALFANUMERICO | CANCELLETTO );", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:118:4: ALFANUMERICO
                    {
                    ALFANUMERICO1=(Token)input.LT(1);
                    match(input,ALFANUMERICO,FOLLOW_ALFANUMERICO_in_porta344); 
                    nome=ALFANUMERICO1.getText();

                    }
                    break;
                case 2 :
                    // /Users/danielederuschi/Documents/UniBg/Progetto di linguaggi e compilatori/Sources/PorteLogiche.g:119:5: CANCELLETTO
                    {
                    CANCELLETTO2=(Token)input.LT(1);
                    match(input,CANCELLETTO,FOLLOW_CANCELLETTO_in_porta353); 
                    nome=CANCELLETTO2.getText();

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return nome;
    }
    // $ANTLR end porta


 

    public static final BitSet FOLLOW_pl_in_expr149 = new BitSet(new long[]{0x0000000000000012L});
    public static final BitSet FOLLOW_PUNTOVIRGOLA_in_expr152 = new BitSet(new long[]{0x0000000000000700L});
    public static final BitSet FOLLOW_pl_in_expr154 = new BitSet(new long[]{0x0000000000000012L});
    public static final BitSet FOLLOW_pln_in_pl169 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_pla_in_pl178 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_plo_in_pl184 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NOT_in_pln200 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_APERTA_in_pln204 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_pln208 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_VIRGOLA_in_pln212 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_pln216 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_CHIUSA_in_pln221 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_AND_in_pla236 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_APERTA_in_pla241 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_pla245 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_VIRGOLA_in_pla249 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_pla253 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_VIRGOLA_in_pla257 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_pla261 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_CHIUSA_in_pla266 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_OR_in_plo282 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_APERTA_in_plo286 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_plo290 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_VIRGOLA_in_plo296 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_plo300 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_VIRGOLA_in_plo306 = new BitSet(new long[]{0x0000000000001800L});
    public static final BitSet FOLLOW_porta_in_plo310 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_CHIUSA_in_plo317 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ALFANUMERICO_in_porta344 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_CANCELLETTO_in_porta353 = new BitSet(new long[]{0x0000000000000002L});

}